package besta.moon.engine.selector;

import besta.moon.engine.RowSource;
import besta.moon.sql.expression.ExpressionName;
import besta.moon.MoonConnection;
import besta.moon.engine.View;
import besta.moon.sql.datatype.MutableNumeric;
import besta.moon.sql.expression.Expressions;

public abstract class DataSource extends RowSource {

    public abstract boolean isNull(int colIdx) throws Exception;

    public abstract boolean getBoolean(int colIdx) throws Exception;

    public abstract int getInt(int colIdx) throws Exception;

    public abstract long getLong(int colIdx) throws Exception;

    public abstract float getFloat(int colIdx) throws Exception;

    public abstract double getDouble(int colIdx) throws Exception;

    public abstract long getMoney(int colIdx) throws Exception;

    public abstract MutableNumeric getNumeric(int colIdx) throws Exception;

    public abstract Object getObject(int colIdx) throws Exception;

    public abstract String getString(int colIdx) throws Exception;

    public abstract byte[] getBytes(int colIdx) throws Exception;

    public abstract int getDataType(int colIdx);

    public boolean init(MoonConnection con) throws Exception {
        return false;
    }

    public String getAlias() {
        return null;
    }

    public abstract View getTableView();

    @Override
    public boolean isExpressionsFromThisRowSource(Expressions columns) {
        for (int i = 0; i < columns.size(); i++) {
            ExpressionName expr = (ExpressionName) columns.get(i);
            if (this != expr.getDataSource()) {
                return false;
            }
        }
        return true;
    }

}
